package com.wxdc.nmgyt.nmgytwydc.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wxdc.nmgyt.nmgytwydc.R;
import com.wxdc.nmgyt.nmgytwydc.model.JcdInfoBean;

import java.util.List;

/**
 * Created by Administrator on 2018/11/30.
 */

public class WaitCommitData_RecyclerViewAdapter extends RecyclerView.Adapter<WaitCommitData_RecyclerViewAdapter.Vholder> implements View.OnClickListener {
    private Context mContext;
    private List<JcdInfoBean> mJcdInfoBeans;
    private RcyclerViewOnClickListener mViewOnClickListener;
    public WaitCommitData_RecyclerViewAdapter(Context context, List<JcdInfoBean> jcdInfoBeans) {
        mContext = context;
        mJcdInfoBeans = jcdInfoBeans;
    }
    public interface RcyclerViewOnClickListener{
        void onClick(View view);
    }
    @NonNull
    @Override
    public Vholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater lf = LayoutInflater.from(mContext);
        View view = lf.inflate(R.layout.waitcommitdata_recyclerview_item, parent, false);
        return new Vholder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Vholder holder, int position) {
        JcdInfoBean obj = mJcdInfoBeans.get(position);
        holder.mView.setTag(position);
        holder.commitTxt.setTag(position);
        holder.bind(obj);
    }

    @Override
    public int getItemCount() {
        return mJcdInfoBeans == null ? 0 : mJcdInfoBeans.size();
    }

    @Override
    public void onClick(View v) {
        if (mViewOnClickListener != null) {
            mViewOnClickListener.onClick(v);
        }
    }

    //--------------------------------------------------------------------------------------------
    class Vholder extends RecyclerView.ViewHolder{
        private View mView;
        private TextView jcdNameTxt,commitTxt;
        public Vholder(View itemView) {
            super(itemView);
            this.mView = itemView;
            jcdNameTxt = itemView.findViewById(R.id.wcr_rv_item_jcdname_txt);
            commitTxt = itemView.findViewById(R.id.wcr_rv_item_commit_txt);
            mView.setOnClickListener(WaitCommitData_RecyclerViewAdapter.this::onClick);
            commitTxt.setOnClickListener(WaitCommitData_RecyclerViewAdapter.this::onClick);
        }
        public void bind(JcdInfoBean infoBean){
            jcdNameTxt.setText(infoBean.getGEMNAME());
        }
    }
    //--------------------------------------------------------------------------------------------
    public void setOnClickListener(RcyclerViewOnClickListener onClickListener){
        this.mViewOnClickListener = onClickListener;
    }
}
